#include <stdio.h>
#include <string.h> 
int main()
{
	int n,m,t;
	scanf("%d %d %d",&n,&m,&t);
	int cpr1[n],cpr2[m],multi1[n],multi2[m];
	int index1=0;
	for(int i=0;i<2*n;i++)
	{
		if(i%2==0)
		{
			scanf("%d",&cpr1[index1]);
		}
		else
		{            
			scanf("%d",&multi1[index1]);
			index1++;
		}
	}
	int index2=0;
	for(int i=0;i<2*m;i++)
	{
		if(i%2==0)
		{
			scanf("%d",&cpr2[index2]);
		}
		else
		{
			scanf("%d",&multi2[index2]);
			index2 ++;
		}
	}	
	int new_cpr[20],new_multi[20];
	if(t==0)
	{
	 for(int i=0;i<n;i++)
	 {
	 	int aim=0;
	 	for(int j=0;j<m;j++)
	 	{
	 		if(multi1[i]==multi2[j])
	 		{
	 			new_cpr[i]=cpr1[i]+cpr2[j];
	 			aim=1;
	 			break;
			 }
		 }
		 if(aim==0)
		 {
		 	new_cpr[i]=cpr1[i];
		 }
	 }
}
	 else
	 {
	 	for(int i=0;i<n;i++)
	 {
	 	int aim=0;
	 	for(int j=0;j<m;j++)
	 	{
	 		if(multi1[i]==multi2[j])
	 		{
	 			new_cpr[i]=cpr1[i]-cpr2[j];
	 			aim=1;
	 			break;
			 }
		 }
		 if(aim==0)
		 {
		 	new_cpr[i]=cpr1[i];
		 }
	 }
	}
	for(int i=0;i<n;i++)
	{
		new_multi[i]=multi1[i];
	}
	char outcome[100];
	int index=0;
	for(int i=0;i<n;i++)
	{
		if(new_cpr[i]!=0)
		{
			if(new_cpr[i]==1)
			{
				if(new_multi[i]!=0)
				{
					if(new_multi[i]==1)
					{
						index+=sprintf(&outcome[index],"%c%c",'x','+');
					}
					else
					{
					index+=sprintf(&outcome[index],"%c%c%d%c",'x','^',new_multi[i],'+');
				    }
				}
				else
				{
					index+=sprintf(&outcome[index],"%d%c",new_cpr[i],'+');
				}
			}
			else
		    {
			if(new_multi[i]!=0)
			{
				if(new_multi[i]==1)
				{
					index+=sprintf(&outcome[index],"%d%c%c",new_cpr[i],'x','+');
				}
				else
				{
		  	        index+=sprintf(&outcome[index],"%d%c%c%d%c",new_cpr[i],'x','^',new_multi[i],'+');
		        }
		    }
		  else
		  {
		  	index+=sprintf(&outcome[index],"%d%c",new_cpr[i],'+');
		  }
	        }
		}
	}


	outcome[index-1]='\0';
	printf("%s",outcome);
	return 0;
}
